package com.wenjing.xiaoyun.chat.config;

import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 会话隔离
 */
@Configuration
public class XiaoYunChatAssistantConfig {
    private final MongoChatMemoryConfig mongoChatMemoryConfig;

    public XiaoYunChatAssistantConfig(MongoChatMemoryConfig mongoChatMemoryConfig) {
        this.mongoChatMemoryConfig = mongoChatMemoryConfig;
    }

    @Bean
    ChatMemoryProvider xiaoYunChatMemoryProvider() {
        return memoryId -> MessageWindowChatMemory.builder()
                .id(memoryId)
                .maxMessages(20)
                .chatMemoryStore(mongoChatMemoryConfig)//配置持久化对象
                .build();
    }
}
